import Logger from '@/helper/Logger';

export default async (ctx,next) => {
    try{
        await next();
    }catch(error){
        if (401 == error.status) {
            // ctx.status = 401;
            ctx.body = {
                code: 401,
                msg: "未登录"
            }
        } else {
            // ctx.status = error.status || 500;
            Logger.error(error);
            if(error instanceof Error){
                ctx.body = {
                    code: 500,
                    msg: error.message
                }
            }else{
                ctx.body = error;
            }
        }
    }
}